import logging
import time

from django.contrib.auth import aauthenticate
from selenium import webdriver
import unittest
from Page1 import Page1
from ddt import ddt,file_data
from Tools import Tools

@ddt
class Case(unittest.TestCase):
    def setUp(self):
        print('start case')
        Tools().Log()
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
    def tearDown(self):
        print('end case')
        time.sleep(5)
        self.driver.quit()
    # 登录后，添加销售机会信息，添加成功！
    @file_data('./login.yaml')
    def test_01(self,username,password,exp):
        logging.info('start case test_01')
        po = Page1(self.driver)
        po.open_url('http://localhost:8081/lxyk5Slist')
        time.sleep(2)
        po.login_luoji(username,password)
        if exp == '正':
            # 1.点击添加按钮
            po.add_sale()
            time.sleep(2)
            # 2.输入客户id
            po.userid()
            time.sleep(2)
            # 3.输入产品id
            po.productid()
            time.sleep(2)
            # 4.点击销售状态框
            po.statusK()
            time.sleep(2)
            # 5.点击选择状态
            po.status()
            time.sleep(2)
            # 6.输入预期收益
            po.shouyi()
            time.sleep(2)
            # 7.点击提交按钮
            po.commit()
            time.sleep(2)
            # 处理弹窗
            alert = self.driver.switch_to.alert
            alert.accept()
            logging.info('end case test_01')
        else:
            logging.info('end case test_01')
            return



if __name__ == '__main__':
    unittest.main()